import { UIPool } from "../etc/UIPool";
import RankItem_Generate from "../ui-generate/worldUI/RankItem_generate";
import RankUI_Generate from "../ui-generate/worldUI/RankUI_generate";

export interface RankInfo{
    name:string
    rank:number
}

export class RankWindow extends RankUI_Generate{
    private pool:UIPool<RankItem> = new UIPool(()=>{
        let item = UIService.create(RankItem)
        this.con_items.addChild(item.uiObject)
        return item
    })

    refresh(info:RankInfo[]){
        this.pool.resetAll()
        for (let i = 0; i < info.length; i++) {
            let datum = info[i]
            this.pool.get().setInfo(i,datum)
        }
    }
}

class RankItem extends RankItem_Generate{
    setInfo(index:number, info:RankInfo){
        if(index > 2){
            this.img_icon.visibility = SlateVisibility.Collapsed
        }else{
            this.img_icon.visibility = SlateVisibility.SelfHitTestInvisible
            if(index == 0){
                this.img_icon.imageGuid = '151905'
            }
            else if(index == 1){
                this.img_icon.imageGuid = '151984'
            }
            else if(index == 2){
                this.img_icon.imageGuid = '151986'
            }
        }

        this.txt_name.text = info.name
        this.txt_rank.text = `${info.rank}米`
    }
}